import pyautogui as pg
import os
import time
import pyperclip
import requests
import json
import psutil
import sys
import win32gui
import win32con
from pywinauto.application import Application

def check_project_number_is_null():
    time.sleep(2)
    # pg.hotkey("tab")
    # pg.hotkey("tab")
    pyperclip.copy("none")
    pg.hotkey("right")
    time.sleep(1)
    pg.hotkey("right")
    # 解锁单元格
    pg.hotkey("shift", "F10")
    pg.hotkey("w")
    pg.hotkey("space")
    pg.hotkey("ctrl", "c")
    number = pyperclip.paste()
    if number != "none" :
        return
    else :
        i = 1
        retry = 0
        while True :
            pyperclip.copy("none")
            pg.hotkey("ctrl", "c")
            pre_number = pyperclip.paste()
            if (pre_number != "none" and pre_number != " " and pre_number != "  ") :
                retry += 1
                i -= 1
                if retry >= 2 :
                    break
            pyperclip.copy(str(i))
            time.sleep(1)
            pg.hotkey("ctrl", "v")
            if i == 1 :
                pyperclip.copy("none")
                # 检测是否输入成功
                time.sleep(1)
                pg.hotkey("ctrl", "a")
                pg.hotkey("ctrl", "c")
                # print(pyperclip.paste())none
                if (pyperclip.paste() != str(i)) :
                    pg.hotkey("enter")
                    pg.hotkey("right")
                    time.sleep(1)
                    # 解锁单元格
                    pg.hotkey("shift", "F10")
                    pg.hotkey("w")
                    pg.hotkey("space")
                    i = 1 
                    continue
            pg.hotkey("enter")
            pg.hotkey("down")
            time.sleep(1)
            # 解锁单元格
            pg.hotkey("shift", "F10")
            pg.hotkey("w")
            pg.hotkey("space")
            time.sleep(2)
            if i > 100:
                raise Exception('too many project numbers need to be filled in')
            i += 1
